/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ItemManager.java
 *
 * Created on 20-Mar-2011, 20:02:43
 */

package inventorymanagement;

import DataAccess.AccessDB;
import DataAccess.DBUtil;
import Entity.Category;
import Entity.InfoDatabase;
import Entity.Items;
import interact.iCheckForm;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author dung
 */
public class ItemManager extends javax.swing.JFrame {
    String flag = "";
    DefaultTableModel MTableCate = new DefaultTableModel();
    DefaultTableModel MTableItems = new DefaultTableModel();
    AccessDB accessDB = new AccessDB();
    InfoDatabase idb = DBUtil.getInfoDB();
    Items itManager;
    Category cateManager = new Category();
    /** Creates new form ItemManager */
    public ItemManager() {
        initComponents();
        LoadItems();
    }

    public void InsertItems(){
        
        try{
        String strBug="";
        String itName = txtItemName.getText();
        String Unit = cboItemUnit.getSelectedItem().toString();

        String des = txaItemDescipt.getText();
        String manu = txtItemManu.getText();
        float itPrice = Float.parseFloat(txtItemPrice.getText());
        int itCateID = Integer.parseInt(txtCateID.getText());
        if(itPrice<0)
        {
            JOptionPane.showMessageDialog(null, "Invalid Price","Error",JOptionPane.ERROR_MESSAGE);
            this.dispose();
        }
//        System.out.println(manu);
//        System.out.println(itPrice);
//        boolean active = true;
        itManager = new Items(itCateID, itName,0, itPrice, des, manu, true, Unit);
        if(flag=="AddItem")
        {
            accessDB.InsertItems(itManager);
        }
        else if(flag=="EditItem")
        {
            accessDB.UpdateItem(itManager);
        }
        }catch(Exception ex)
        {
           JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    public void InsertCate()
    {
        
        try{
        
        String cateName = txtCategoriesName.getText();
        cateManager.setCategoryName(cateName);
        if(flag=="AddCate"){

            accessDB.InsertCate(cateManager);
        }
        else if(flag=="EditCate"){
            int cateID = Integer.parseInt(txtCateID.getText());
            cateManager.setCategoryID(cateID);
            accessDB.UpdateCate(cateManager);
        }
        }
        catch(Exception ex)
        {
           JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
        }
    private void LoadItems() {
        accessDB.SelectCategories(MTableCate);
        accessDB.SelectItems(MTableItems);
//        if(nRows==0)
//            return;
//        if(nRows>=0)
//        {
//            ListSelectionModel selectionModel = tblAccount.getSelectionModel();
//            selectionModel.setSelectionInterval(0, 0);
////            txtAAccount.setText(tblAccount.getValueAt(nRows, nRows));
//        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        txtItemManu = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txtItemName = new javax.swing.JTextField();
        txtItemPrice = new javax.swing.JTextField();
        btnItemAdd = new javax.swing.JButton();
        btnItemEdit = new javax.swing.JButton();
        btnItemSave = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        txaItemDescipt = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        txtCateID = new javax.swing.JTextField();
        btnItemCancel = new javax.swing.JButton();
        cboItemUnit = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCategories = new javax.swing.JTable();
        btnCateAdd = new javax.swing.JButton();
        btnCateEdit = new javax.swing.JButton();
        btnCateSave = new javax.swing.JButton();
        btnCateCancel = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        txtCategoriesName = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblItems = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Item Manager ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Items", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel5.setText("Manufacture");

        jLabel4.setText("Descript :");

        jLabel3.setText("Price:");

        jLabel2.setText("Unit");

        jLabel1.setText("Item Name:");

        txtItemName.setEditable(false);

        btnItemAdd.setText("Add");
        btnItemAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnItemAddActionPerformed(evt);
            }
        });

        btnItemEdit.setText("Edit");
        btnItemEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnItemEditActionPerformed(evt);
            }
        });

        btnItemSave.setText("Save");
        btnItemSave.setEnabled(false);
        btnItemSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnItemSaveActionPerformed(evt);
            }
        });

        txaItemDescipt.setColumns(20);
        txaItemDescipt.setRows(5);
        jScrollPane3.setViewportView(txaItemDescipt);

        jLabel7.setText("CategoryID:");

        txtCateID.setEditable(false);

        btnItemCancel.setText("Cancel");
        btnItemCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnItemCancelActionPerformed(evt);
            }
        });

        cboItemUnit.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KG", "Litter", "Pieces", "Meters" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnItemAdd)
                        .addGap(18, 18, 18)
                        .addComponent(btnItemEdit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnItemSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnItemCancel))
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtItemManu, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtItemPrice, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtItemName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE))
                    .addComponent(txtCateID, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboItemUnit, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(90, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtItemName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cboItemUnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(txtItemPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtItemManu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7)
                    .addComponent(txtCateID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnItemCancel)
                    .addComponent(btnItemAdd)
                    .addComponent(btnItemEdit)
                    .addComponent(btnItemSave))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Categories", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        tblCategories.setModel(MTableCate);
        tblCategories.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblCategoriesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblCategories);

        btnCateAdd.setText("Add");
        btnCateAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCateAddActionPerformed(evt);
            }
        });

        btnCateEdit.setText("Edit");
        btnCateEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCateEditActionPerformed(evt);
            }
        });

        btnCateSave.setText("Save");
        btnCateSave.setEnabled(false);
        btnCateSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCateSaveActionPerformed(evt);
            }
        });

        btnCateCancel.setText("Cancel");
        btnCateCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCateCancelActionPerformed(evt);
            }
        });

        jLabel6.setText("Categories Name:");

        txtCategoriesName.setEditable(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGap(48, 48, 48)
                                .addComponent(btnCateAdd)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                .addComponent(btnCateEdit)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnCateSave)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnCateCancel)
                                .addGap(77, 77, 77))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(txtCategoriesName, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(58, 58, 58)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtCategoriesName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(51, 51, 51)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCateEdit)
                    .addComponent(btnCateSave)
                    .addComponent(btnCateCancel)
                    .addComponent(btnCateAdd))
                .addContainerGap(40, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 412, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tblItems.setModel(MTableItems);
        tblItems.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblItemsMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblItems);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        getContentPane().add(jPanel1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnItemAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnItemAddActionPerformed
        // TODO add your handling code here:
        txtItemName.setEditable(true);
        txtItemName.setText("");
        txtItemManu.setText("");
        txtCateID.setText("");
        txtItemPrice.setText("");
        cboItemUnit.setSelectedIndex(1);
        txaItemDescipt.setText("");
        btnItemAdd.setEnabled(false);
        btnItemEdit.setEnabled(false);
        btnItemSave.setEnabled(true);
        flag="AddItem";
    }//GEN-LAST:event_btnItemAddActionPerformed

    private void btnItemSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnItemSaveActionPerformed
        // TODO add your handling code here:
        String strBug="";
        if(txtItemName.getText().equals(""))
        {
            strBug+="\n Item Name Invalid";
        }
        if(txtItemManu.getText().equals(""))
        {
            strBug+="\n Manufactor Invalid";
        }
        if(txtCategoriesName.getText().equals(""))
        {
            strBug+="\n Plase select a Category";
        }
        if(iCheckForm.checkNumber(txtItemPrice.getText())||txtItemPrice.getText().equals(""))
        {
            strBug+="\n Price Invalid";
        }
        if(txaItemDescipt.getText().equals(""))
        {
            strBug+="\n Description invalid";
        }
        if(!strBug.equals("")){
            JOptionPane.showMessageDialog(null, strBug,"Error",JOptionPane.ERROR_MESSAGE);
        }
        else if(strBug.equals(""))
        {
            InsertItems();
            accessDB.RefeshItem(tblItems);
        }
    }//GEN-LAST:event_btnItemSaveActionPerformed

    private void btnItemEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnItemEditActionPerformed
        // TODO add your handling code here:
        btnItemAdd.setEnabled(false);
        btnItemEdit.setEnabled(false);
        btnItemSave.setEnabled(true);
        flag = "EditItem";
    }//GEN-LAST:event_btnItemEditActionPerformed

    private void tblItemsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblItemsMouseClicked
        // TODO add your handling code here:
        int i = tblItems.getSelectedRow();
        txtItemName.setText(String.valueOf(tblItems.getValueAt(i, 2)));
        txtItemManu.setText(String.valueOf(tblItems.getValueAt(i, 6)));
        cboItemUnit.setSelectedItem(String.valueOf(tblItems.getValueAt(i, 8)));
        txtItemPrice.setText(String.valueOf(tblItems.getValueAt(i, 4)));
        txaItemDescipt.setText(String.valueOf(tblItems.getValueAt(i, 5)));
        txtCateID.setText(String.valueOf(tblItems.getValueAt(i, 1)));
        btnItemEdit.setEnabled(true);

    }//GEN-LAST:event_tblItemsMouseClicked

    private void tblCategoriesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblCategoriesMouseClicked
        // TODO add your handling code here:
        int i = tblCategories.getSelectedRow();
        txtCateID.setText(String.valueOf(tblCategories.getValueAt(i, 0)));
        txtCategoriesName.setText(String.valueOf(tblCategories.getValueAt(i, 1)));
    }//GEN-LAST:event_tblCategoriesMouseClicked

    private void btnCateAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCateAddActionPerformed
        // TODO add your handling code here:
        btnCateAdd.setEnabled(false);
        btnCateEdit.setEnabled(false);
        btnCateSave.setEnabled(true);
        txtCategoriesName.setEditable(true);
        txtCategoriesName.setText("");
        flag="AddCate";
    }//GEN-LAST:event_btnCateAddActionPerformed

    private void btnCateEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCateEditActionPerformed
        // TODO add your handling code here:
        btnCateAdd.setEnabled(false);
        btnCateEdit.setEnabled(false);
        btnCateSave.setEnabled(true);
        txtCategoriesName.setEditable(true);
        flag ="EditCate";
    }//GEN-LAST:event_btnCateEditActionPerformed

    private void btnCateCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCateCancelActionPerformed
        // TODO add your handling code here:
        btnCateAdd.setEnabled(false);
        btnCateEdit.setEnabled(false);
        btnCateSave.setEnabled(true);
        txtCategoriesName.setEditable(false);
    }//GEN-LAST:event_btnCateCancelActionPerformed

    private void btnCateSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCateSaveActionPerformed
        // TODO add your handling code here:
        if(txtCategoriesName.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Invalid CategoryName","Error",JOptionPane.ERROR_MESSAGE);
        }
        else{
        InsertCate();
        accessDB.RefeshCate(tblCategories);
        }
    }//GEN-LAST:event_btnCateSaveActionPerformed

    private void btnItemCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnItemCancelActionPerformed
        // TODO add your handling code here:
        btnItemAdd.setEnabled(true);
        btnItemEdit.setEnabled(true);
        btnItemSave.setEnabled(false);
        txtItemName.setText("");
        txtItemName.setEditable(false);
        txtItemPrice.setText("");
        txaItemDescipt.setText("");
        txtItemManu.setText("");
        txtCateID.setText("");
        cboItemUnit.setSelectedIndex(1);
    }//GEN-LAST:event_btnItemCancelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ItemManager().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCateAdd;
    private javax.swing.JButton btnCateCancel;
    private javax.swing.JButton btnCateEdit;
    private javax.swing.JButton btnCateSave;
    private javax.swing.JButton btnItemAdd;
    private javax.swing.JButton btnItemCancel;
    private javax.swing.JButton btnItemEdit;
    private javax.swing.JButton btnItemSave;
    private javax.swing.JComboBox cboItemUnit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable tblCategories;
    private javax.swing.JTable tblItems;
    private javax.swing.JTextArea txaItemDescipt;
    private javax.swing.JTextField txtCateID;
    private javax.swing.JTextField txtCategoriesName;
    private javax.swing.JTextField txtItemManu;
    private javax.swing.JTextField txtItemName;
    private javax.swing.JTextField txtItemPrice;
    // End of variables declaration//GEN-END:variables

}
